# 两电阻并联阻值计算
from flask import Flask, render_template, request
from wtforms import FloatField, SubmitField  # 类型
from flask_wtf import FlaskForm
from wtforms.validators import DataRequired  # 验证数据

app = Flask(__name__)
app.config['SECRET_KEY'] = 'ADJLAJDLA'


class Circuit(FlaskForm):
    first = FloatField(label='值', validators=[DataRequired('电阻值不能为空')])
    second = FloatField(label='值', validators=[DataRequired('电阻值不能为空')])
    result = FloatField(label='值')
    submit = SubmitField(label='计算')


@app.route('/', methods=['GET', 'POST'])
def circuit():
    form = Circuit()
    if request.method == 'GET':
        form.result.data = 0
        return render_template('parallel resistance.html', form=form)
    if request.method == 'POST':
        value1 = form.first.data
        value2 = form.second.data
        print('R1:', value1)
        print('R2:', value2)
        form.result.data = 1 / ((1 / value1) + (1 / value2))
        return render_template('Circuit002.html', form=form)


if __name__ == '__main__':
    app.run()
